package com.wxapp.gateway.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author lgl
 * @Description
 * @DateTime 2023/4/17 15:33
 * @Modified By
 */
@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter setCorsWeb() {
        var source = new UrlBasedCorsConfigurationSource();
        var config = new CorsConfiguration();
        config.addAllowedMethod(CorsConfiguration.ALL);
        config.addAllowedHeader(CorsConfiguration.ALL);
        config.addAllowedOrigin(CorsConfiguration.ALL);
        config.addAllowedOriginPattern(CorsConfiguration.ALL);
        config.addExposedHeader(CorsConfiguration.ALL);
        source.registerCorsConfiguration("/**", config);
        return new CorsWebFilter(source);
    }
}
